package com.gmail.blackdog1987.carcare.network.request.builder;

import android.content.Context;

import com.gmail.blackdog1987.carcare.Constant;
import com.gmail.blackdog1987.carcare.network.request.RequestBuilder;
import com.gmail.blackdog1987.carcare.util.DeviceUtils;
import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class RegRequestBuilder extends RequestBuilder {

	private static final String TAG = RegRequestBuilder.class.getSimpleName();
	private String username; //
	private String pwd; //
	private String code;
	private String cartype;
	private String carnumber;
	private String enginenumber;
	private String carbonenumber;

	@Override
	public RequestParams buildRquest() {
		RequestParams params = new RequestParams();
		params.put("username", username);
		params.put("pwd", pwd);
		params.put("code", code);
		params.put("cartype", cartype);
		params.put("carnumber", carnumber);
		params.put("enginenumber", enginenumber);
		params.put("carbonenumber", carbonenumber);
		return params;
	}

	@Override
	public void postJsonRequest(Context context, AsyncHttpResponseHandler handler) {

		RequestParams params = buildRquest();

		AsyncHttpClient client = new AsyncHttpClient();
		client.setTimeout(Constant.TIMEOUT);
		client.setUserAgent(DeviceUtils.OS.getName());

		client.post(Constant.Action.REG, params, handler);
		LogUtil.d(TAG, "post : " + params);
	}

	public RegRequestBuilder setUsername(String username) {
		this.username = username;
		return this;
	}

	public RegRequestBuilder setPwd(String pwd) {
		this.pwd = pwd;
		return this;
	}

	public RegRequestBuilder setCode(String code) {
		this.code = code;
		return this;
	}

	public RegRequestBuilder setCartype(String cartype) {
		this.cartype = cartype;
		return this;
	}

	public RegRequestBuilder setCarnumber(String carnumber) {
		this.carnumber = carnumber;
		return this;
	}

	public RegRequestBuilder setEnginenumber(String enginenumber) {
		this.enginenumber = enginenumber;
		return this;
	}

	public RegRequestBuilder setCarbonenumber(String carbonenumber) {
		this.carbonenumber = carbonenumber;
		return this;
	}
}
